const MAX = 6 // 最大缓存数
export default {
  data() {
    return {
      historicCity: [] // 历史城市
    }
  },
  methods: {
    initHistoricCity() {
      let historicCity = uni.getStorageSync('historicCity') || []
      const checkCity = this.$auth.getChooseAreaInfo()
      historicCity.push(checkCity)
      console.log('historicCity_push', historicCity)
      historicCity = this.$utils.deDupArray(historicCity, 'cityId')
      historicCity.unshift(historicCity.pop()) // 保证当然定位城市在历史城市第一个
      this.historicCity = historicCity.slice(0, MAX)
    },

    saveHistoricCity() {
      const historicCity = this.historicCity
      console.log('historicCity_save', historicCity)
      uni.setStorageSync('historicCity', historicCity)
    },

    pushHistoricCity(item) {
      let historicCity = this.$utils.deep(this.historicCity)
      historicCity.unshift(item)
      historicCity = this.$utils.deDupArray(historicCity, 'cityId')
      historicCity = historicCity.slice(0, MAX)
      this.historicCity = historicCity
      this.saveHistoricCity()
    }
  }
}
